package cn.linstudy.service.impl;

import cn.linstudy.dao.EmployeeMapper;
import cn.linstudy.domain.Department;
import cn.linstudy.domain.Employee;
import cn.linstudy.qo.EmployeeQueryObject;
import cn.linstudy.qo.PageResult;
import cn.linstudy.result.ResponseResult;
import cn.linstudy.service.EmployeeService;
import java.util.Collections;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Description
 * @Author XiaoLin
 * @Date 2021/3/2 17:04
 */
@Service
public class EmployeeServiceImpl implements EmployeeService {

  @Autowired
  EmployeeMapper employeeMapper;
  @Override
  public ResponseResult add(Employee employee) {
    return new ResponseResult(200,"添加成功",employeeMapper.insert(employee));
  }

  @Override
  public ResponseResult delete(Long id) {
    return new ResponseResult(200,"删除成功",employeeMapper.deleteByPrimaryKey(id));
  }

  @Override
  public ResponseResult update(Employee employee) {
    return new ResponseResult(200,"修改成功",employeeMapper.updateByPrimaryKeySelective(employee));
  }


  @Override
  public ResponseResult listOneById(Long id) {
    return new ResponseResult(200,"修改成功",employeeMapper.selectByPrimaryKey(id));
  }

  @Override
  public PageResult<Employee> listForPage(EmployeeQueryObject qo) {
    int count = employeeMapper.listForCount(qo);
    if (count != 0){
      List<Employee> employees = employeeMapper.listForQuery(qo);
      return new PageResult<Employee>(qo.getCurrentPage(),qo.getPageSize(),count,employees);
    }else {
    return new PageResult<Employee>(qo.getCurrentPage(),qo.getPageSize(),0, Collections.emptyList());

    }
  }

  @Override
  public List<Employee> listAll() {
    return employeeMapper.listAll();
  }
}
